package com.map.domain;

import java.io.*;
import java.util.*;

public class Tree implements Serializable{
	
	private Node root;
	
	public Tree() {
        root = null;
    }

	public Tree(Node root) {
        this.root = root;
    }
	
	 public Node getRoot() {
	      return root;
	    }
	 
	 public boolean isLeaf() {
	        return (root == null || (root.children == null));
	    }
	 
	    public int height(Node r) {
	      if (r == null) return 0;
	      return 1;
	    }
	    
	    public int size(Node r) {
	      if (r == null) return 0;
	      return 1;
	    }

		public void addNode(String list []) {
			
			System.out.println(list.length);
			Node curr = null;
			curr = root;
			for (int i = list.length - 1; i>=0; i--) {
				Node temp = null;
				System.out.println(list[i]);
				temp = curr.hasChild(list[i]);
				if (temp != null) {
					System.out.println("The current node already has this node");
					curr = temp;
				}
				else {
					temp = new Node(list[i]);
					curr.addChild(temp);
					curr = temp;
				}
			}
		}

}
